package com.jiangxiaofei.citycloud.activity.freshfruits;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.jiangxiaofei.citycloud.R;
import com.jiangxiaofei.citycloud.base.BaseActivity;
import com.jiangxiaofei.citycloud.bean.NeedBean;
import com.jiangxiaofei.citycloud.constants.StringConstants;
import com.jiangxiaofei.citycloud.mvp.FreshConstant;
import com.jiangxiaofei.citycloud.mvp.FreshPersenter;
import com.jiangxiaofei.citycloud.util.PermissionUtil;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * @author: JiangXFei
 * @date: 2017/11/21 0021
 * @content:需求详情页
 */

public class FreshFruitsNeedDetailActivity extends BaseActivity
        implements FreshConstant.GetFreshNeedDetailView {
    @InjectView(R.id.tv_need_title)
    TextView tvNeedTitle;
    @InjectView(R.id.tv_need_price)
    TextView tvNeedPrice;
    @InjectView(R.id.tv_need_location)
    TextView tvNeedLocation;
    @InjectView(R.id.tv_need_time)
    TextView tvNeedTime;
    @InjectView(R.id.tv_need_look_count)
    TextView tvNeedLookCount;
    @InjectView(R.id.tv_need_content)
    TextView tvNeedContent;
    @InjectView(R.id.tv_qq)
    TextView tvQq;
    @InjectView(R.id.tv_call)
    TextView tvCall;
    private int needId;
    private String phoneNum;

    FreshConstant.GetFreshNeedDetailPersenter getFreshNeedDetailPersenter;

    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_fresh_fruits_need_detail_layout);
        mActivity = this;
        mContext = this;
        initTitle();
        ButterKnife.inject(this);
        Intent intent = getIntent();
        needId = intent.getIntExtra(StringConstants.FRESHNEEDID, -1);
        getFreshNeedDetailPersenter =
                new FreshPersenter(mContext, (FreshConstant.GetFreshNeedDetailView) mActivity);
        getFreshNeedDetailPersenter.getNeedDetail();
    }

    @Override
    protected void setListener() {

    }

    @OnClick({R.id.tv_call})
    public void bOnClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.tv_call:
                initDetailPopup(v1 -> {
                    mPopupWindowPublish.dismiss();
                    PermissionUtil.CallPhone(mContext, phoneNum);
                }, v2 -> {
                    mPopupWindowPublish.dismiss();
                    PermissionUtil.sendMsg(mContext, phoneNum);
                }, v3 -> {
                    mPopupWindowPublish.dismiss();
                });
                showDetailPopup();
                break;
        }
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        setLeftOneBg(R.drawable.ic_back_black);
        setCTitle("商品信息");
        mCenterTitle.setTextColor(Color.parseColor("#7b7b7b"));
        rl_layout.setBackgroundColor(Color.parseColor("#ffffff"));
    }

    @Override
    public void setData(Object o) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void message(String str) {

    }

    @Override
    public int getNeedDetailId() {
        return needId;
    }

    @Override
    public void getNeedSuccess(NeedBean needBean) {
        tvNeedTitle.setText(needBean.getTitle());
        tvNeedContent.setText(needBean.getDescription());
        tvNeedTime.setText(needBean.getIssue());
        tvNeedLookCount.setText(needBean.getVisitors());
        tvNeedLocation.setText(needBean.getProarea());
        tvNeedPrice.setText(needBean.getPrice());
        phoneNum = needBean.getPhonenum();
    }
}
